home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE1 / EASYC / !EasyC++ / h / iostream < prev    next >
Text File  |  1994-11-24  |  9KB  |  237 lines

  1. //    This is part of the iostream library, providing -*- C++ -*- input/output.
  2. //    Copyright (C) 1991 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #ifndef _IOSTREAM_H
  19. #ifdef __GNUG__
  20. #pragma interface
  21. #endif
  22. #define _IOSTREAM_H
  23. extern "C" int printf (const char *format ...) ;
  24.  
  25. #include <streambuf.h>
  26.  
  27. class istream; class ostream;
  28. typedef ios& (*__manip)(ios&);
  29. typedef istream& (*__imanip)(istream&);
  30. typedef ostream& (*__omanip)(ostream&);
  31.  
  32. extern istream& ws(istream& ins);
  33. extern ostream& flush(ostream& outs);
  34. extern ostream& endl(ostream& outs);
  35. extern ostream& ends(ostream& outs);
  36.  
  37. class ostream : virtual public ios
  38. {
  39.     // NOTE: If fields are changed, you must fix _fake_ostream in stdstreams.C!
  40.     void do_osfx();
  41.   public:
  42.     ostream() { }
  43.     ostream(streambuf* sb, ostream* tied=NULL);
  44.     int opfx() {
  45.         if (!good()) return 0; else { if (_tie) _tie->flush(); return 1;} }
  46.     void osfx() { if (flags() & (ios::unitbuf|ios::stdio))
  47.                       do_osfx(); }
  48.     streambuf* ostreambuf() const { return _strbuf; }
  49.     ostream& flush();
  50.     ostream& put(char c) { _strbuf->sputc(c); return *this; }
  51. #if 0         // This is apmbiguous (Easy C++)
  52.     ostream& put(unsigned char c) { return put((char)c); }
  53. #endif
  54.     ostream& write(const char *s, int n);
  55.     ostream& write(const unsigned char *s, int n) { return write((const char*)s, n);}
  56. #ifndef _G_BROKEN_SIGNED_CHAR
  57. #if 0               // Also ambiguous
  58.     ostream& put(signed char c) { return put((char)c); }
  59. #endif
  60.     ostream& write(const signed char *s, int n) { return write((const char*)s, n);}
  61. #endif
  62.     ostream& write(const void *s, int n) { return write((const char*)s, n);}
  63.     ostream& seekp(streampos);
  64.     ostream& seekp(streamoff, _seek_dir);
  65.     streampos tellp();
  66.     ostream& form(const char *format ...);
  67.     ostream& vform(const char *format, _G_va_list args);
  68.  
  69.     ostream& operator<<(char c);
  70.     ostream& operator<<(unsigned char c) { return (*this) << (char)c; }
  71. #ifndef _G_BROKEN_SIGNED_CHAR
  72.     ostream& operator<<(signed char c) { return (*this) << (char)c; }
  73. #endif
  74.     ostream& operator<<(const char *s);
  75.     ostream& operator<<(const unsigned char *s)
  76.         { return (*this) << (const char*)s; }
  77. #ifndef _G_BROKEN_SIGNED_CHAR
  78.     ostream& operator<<(const signed char *s)
  79.         { return (*this) << (const char*)s; }
  80. #endif
  81.     ostream& operator<<(void *p);
  82.     ostream& operator<<(int n);
  83.     ostream& operator<<(unsigned int n);
  84.     ostream& operator<<(long n);
  85.     ostream& operator<<(unsigned long n);
  86. #ifdef __GNUG__
  87.     ostream& operator<<(long long n);
  88.     ostream& operator<<(unsigned long long n);
  89. #endif
  90.     ostream& operator<<(short n) {return operator<<((int)n);}
  91.     ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
  92.     ostream& operator<<(double n);
  93.     ostream& operator<<(float n) { return operator<<((double)n); }
  94.     ostream& operator<<(__omanip func) { return (*func)(*this); }
  95.     ostream& operator<<(__manip func) {(*func)(*this); return *this;}
  96.     ostream& operator<<(streambuf*);
  97. };
  98.  
  99. class istream : virtual public ios
  100. {
  101.     // NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C!
  102.     _G_ssize_t _gcount;
  103.  
  104.     int _skip_ws();
  105.   public:
  106.     istream() { _gcount = 0; }
  107.     istream(streambuf* sb, ostream*tied=NULL);
  108.     streambuf* istreambuf() const { return _strbuf; }
  109.     istream& get(char* ptr, int len, char delim = '\n');
  110.     istream& get(unsigned char* ptr, int len, char delim = '\n')
  111.         { return get((char*)ptr, len, delim); }
  112.     istream& get(char& c);
  113.     istream& get(unsigned char& c) { return get((char&)c); }
  114.     istream& getline(char* ptr, int len, char delim = '\n');
  115.     istream& getline(unsigned char* ptr, int len, char delim = '\n')
  116.         { return getline((char*)ptr, len, delim); }
  117. #ifndef _G_BROKEN_SIGNED_CHAR
  118.     istream& get(signed char& c)  { return get((char&)c); }
  119.     istream& get(signed char* ptr, int len, char delim = '\n')
  120.         { return get((char*)ptr, len, delim); }
  121.     istream& getline(signed char* ptr, int len, char delim = '\n')
  122.         { return getline((char*)ptr, len, delim); }
  123. #endif
  124.     istream& read(char *ptr, int n);
  125.     istream& read(unsigned char *ptr, int n) { return read((char*)ptr, n); }
  126. #ifndef _G_BROKEN_SIGNED_CHAR
  127.     istream& read(signed char *ptr, int n) { return read((char*)ptr, n); }
  128. #endif
  129.     istream& read(void *ptr, int n) { return read((char*)ptr, n); }
  130.     // Should get() and/or peek() set failbit and/or eofbit? FIXME!
  131.     istream& get(streambuf& sb, char delim = '\n');
  132.     istream& gets(char **s, char delim = '\n');
  133.     int ipfx(int need) {
  134.         if (!good()) { set(ios::failbit); return 0; }
  135.         if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
  136.         if (!need && (flags() & ios::skipws)) return _skip_ws();
  137.         return 1;
  138.     }
  139.     int ipfx0() { // Optimized version of ipfx(0).
  140.         if (!good()) { set(ios::failbit); return 0; }
  141.         if (_tie) _tie->flush();
  142.         if (flags() & ios::skipws) return _skip_ws();
  143.         return 1;
  144.     }
  145.     int ipfx1() { // Optimized version of ipfx(1). -00-
  146.         if (!good()) { set(ios::failbit); return 0; }
  147.         if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
  148.         return 1;
  149.     }
  150.     int get() { if (!ipfx1()) return EOF;
  151.                 int ch = _strbuf->sbumpc();
  152.                 if (ch == EOF) set(ios::eofbit);
  153.                 return ch; }
  154.     int peek() { if (!ipfx1()) return EOF;
  155.                 int ch = _strbuf->sgetc();
  156.                 if (ch == EOF) set(ios::eofbit);
  157.                 return ch; }
  158.     _G_ssize_t gcount() { return _gcount; }
  159.     istream& ignore(int n=1, int delim = EOF);
  160.     istream& seekg(streampos);
  161.     istream& seekg(streamoff, _seek_dir);
  162.     streampos tellg();
  163.     istream& putback(char ch) {
  164.         if (good() && _strbuf->sputbackc(ch) == EOF) clear(ios::badbit);
  165.         return *this;}
  166.     istream& unget() {
  167.         if (good() && _strbuf->sungetc() == EOF) clear(ios::badbit);
  168.         return *this;}
  169.     istream& scan(const char *format ...);
  170.     istream& vscan(const char *format, _G_va_list args);
  171. #ifdef _STREAM_COMPAT
  172.     istream& unget(char ch) { return putback(ch); }
  173.     int skip(int i);
  174. #endif
  175.  
  176.     istream& operator>>(char*);
  177.     istream& operator>>(unsigned char* p) { return operator>>((char*)p); }
  178. #ifndef _G_BROKEN_SIGNED_CHAR
  179.     istream& operator>>(signed char*p) { return operator>>((char*)p); }
  180. #endif
  181.     istream& operator>>(char& c);
  182.     istream& operator>>(unsigned char& c) {return operator>>((char&)c);}
  183. #ifndef _G_BROKEN_SIGNED_CHAR
  184.     istream& operator>>(signed char& c) {return operator>>((char&)c);}
  185. #endif
  186.     istream& operator>>(int&);
  187.     istream& operator>>(long&);
  188. #ifdef __GNUG__
  189.     istream& operator>>(long long&);
  190. #endif
  191.     istream& operator>>(short&);
  192.     istream& operator>>(unsigned int&);
  193.     istream& operator>>(unsigned long&);
  194. #ifdef __GNUG__
  195.     istream& operator>>(unsigned long long&);
  196. #endif
  197.     istream& operator>>(unsigned short&);
  198.     istream& operator>>(float&);
  199.     istream& operator>>(double&);
  200.     istream& operator>>( __manip func) {(*func)(*this); return *this;}
  201.     istream& operator>>(__imanip func) { return (*func)(*this); }
  202.     istream& operator>>(streambuf*);
  203. };
  204.  
  205.  
  206. class iostream : public istream, public ostream
  207. {
  208.     _G_ssize_t _gcount;
  209.   public:
  210.     iostream() { _gcount = 0; }
  211.     iostream(streambuf* sb, ostream*tied=NULL);
  212. };
  213.  
  214. extern istream cin;
  215. extern ostream cout, cerr, clog; // clog->rdbuf() == cerr->rdbuf()
  216.  
  217. #ifndef NOT_EASY_C
  218. class Iostream_init
  219.    {
  220.    public:
  221.       Iostream_init() ;
  222.       ~Iostream_init() ;
  223.    } ;
  224.  
  225. #else
  226. struct Iostream_init { } ;  // Compatibility hack for AT&T library.
  227. #endif
  228.  
  229. inline ios& dec(ios& i)
  230. { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
  231. inline ios& hex(ios& i)
  232. { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
  233. inline ios& oct(ios& i)
  234. { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
  235.  
  236. #endif /*!_IOSTREAM_H*/
  237.